/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroDeSala.java
 *
 * Created on 31/05/2011, 17:42:43
 */
package Formularios;

import DAO.SalaDAO;
import Logica.Sala;
import java.sql.SQLException;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Claudio
 */
public class CadastroDeSala extends javax.swing.JFrame {

    List<Sala> salas;
    ListSelectionModel lsmSala;
    DefaultTableModel tmSala = new DefaultTableModel(null, new String[]{"id", "tipo", "predio", "andar", "Num.Lugares", "situação"});

    /** Creates new form CadastroDeSala */
    public CadastroDeSala() {
        initComponents();
        setLocationRelativeTo(null);
        desabilitaDados();
        jBAlterar.setEnabled(false);
        jBSalvar.setEnabled(false);
        jBRemover.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jBPesquisar = new javax.swing.JButton();
        jTPesquisar = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTTabela = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jBPesquisa = new javax.swing.JButton();
        jTPesquisar1 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jBNovo = new javax.swing.JButton();
        jBSalvar = new javax.swing.JButton();
        jBAlterar = new javax.swing.JButton();
        jBRemover = new javax.swing.JButton();
        jBFechar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTId = new javax.swing.JTextField();
        jTNumLugares = new javax.swing.JTextField();
        jTPredio = new javax.swing.JTextField();
        jTAndar = new javax.swing.JTextField();
        jCTipo = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jCSituacao = new javax.swing.JComboBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuSala = new javax.swing.JMenuItem();
        jMenuLaboratorio = new javax.swing.JMenuItem();
        jMenuEquipamento = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenu6 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenuSair = new javax.swing.JMenu();

        jPanel4.setBackground(new java.awt.Color(255, 153, 153));

        jBPesquisar.setIcon(new javax.swing.ImageIcon("D:\\Documentos\\UNB\\UNB 5 semestre\\TEC DE PROG\\icones\\pesquisar.png")); // NOI18N
        jBPesquisar.setText("Pesquisar");
        jBPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBPesquisarActionPerformed(evt);
            }
        });

        jTPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTPesquisarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTPesquisar, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBPesquisar)
                .addGap(301, 301, 301))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBPesquisar))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Sala");

        jTTabela.setModel(tmSala);
        jTTabela.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmSala = jTTabela.getSelectionModel();
        lsmSala.addListSelectionListener(new ListSelectionListener() { 
            public void valueChanged(ListSelectionEvent e) { 
                if (! e.getValueIsAdjusting()){ 
                    jTTabelaLinhaSelecionada(jTTabela); 
                } 
            }
        });
        jScrollPane1.setViewportView(jTTabela);

        jPanel5.setBackground(new java.awt.Color(255, 153, 153));

        jBPesquisa.setIcon(new javax.swing.ImageIcon("D:\\Documentos\\UNB\\UNB 5 semestre\\TEC DE PROG\\icones\\pesquisar.png")); // NOI18N
        jBPesquisa.setText("Pesquisar");
        jBPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBPesquisaActionPerformed(evt);
            }
        });

        jTPesquisar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTPesquisar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTPesquisar1, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBPesquisa)
                .addGap(320, 320, 320))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTPesquisar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBPesquisa))
                .addGap(289, 289, 289))
        );

        jPanel1.setBackground(new java.awt.Color(153, 255, 153));

        jBNovo.setText("Novo");
        jBNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNovoActionPerformed(evt);
            }
        });

        jBSalvar.setText("Gravar");
        jBSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalvarActionPerformed(evt);
            }
        });

        jBAlterar.setText("Alterar");
        jBAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAlterarActionPerformed(evt);
            }
        });

        jBRemover.setText("Remover");
        jBRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRemoverActionPerformed(evt);
            }
        });

        jBFechar.setText("Fechar");
        jBFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBFecharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jBNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                .addComponent(jBSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBRemover, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(80, 80, 80)
                .addComponent(jBFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBFechar, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                    .addComponent(jBRemover, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                    .addComponent(jBAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                    .addComponent(jBSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBAlterar, jBFechar, jBNovo, jBRemover, jBSalvar});

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cadastro de Sala", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 13))); // NOI18N

        jLabel1.setText("Código:");

        jLabel2.setText("Número de lugares:");

        jLabel3.setText("Prédio:");

        jLabel4.setText("Andar:");

        jLabel5.setText("Tipo:");

        jTId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTIdActionPerformed(evt);
            }
        });

        jCTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sala de aula", "Sala de reunião", "Auditório" }));

        jLabel6.setText("Situação: ");

        jCSituacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Disponível", "Alugada" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTId, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTNumLugares)
                                .addComponent(jTPredio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(291, 291, 291)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jCTipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTAndar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCSituacao, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(120, 120, 120))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTAndar, jTId, jTNumLugares, jTPredio});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jTId, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTAndar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5)
                    .addComponent(jTNumLugares, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTPredio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)
                        .addComponent(jCSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenu1.setText("Cadastro");

        jMenuSala.setText("Salas");
        jMenuSala.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuSalaMouseClicked(evt);
            }
        });
        jMenuSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuSalaActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuSala);

        jMenuLaboratorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuLaboratorioActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuLaboratorio);

        jMenuEquipamento.setText("Equipamentos");
        jMenuEquipamento.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuEquipamentoMouseClicked(evt);
            }
        });
        jMenuEquipamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuEquipamentoActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuEquipamento);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Reservas");
        jMenuBar1.add(jMenu2);

        jMenu3.setText("Pesquisar");
        jMenuBar1.add(jMenu3);

        jMenu6.setText("Locação");
        jMenuBar1.add(jMenu6);

        jMenu5.setText("Relatórios");
        jMenuBar1.add(jMenu5);

        jMenuSair.setText("Sair");
        jMenuSair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuSairMouseClicked(evt);
            }
        });
        jMenuBar1.add(jMenuSair);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 637, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNovoActionPerformed
        habilitaDados();
        jBSalvar.setEnabled(true);
        jTId.setText("");
        jTAndar.setText("");
        jTNumLugares.setText("");
        jTPredio.setText("");

}//GEN-LAST:event_jBNovoActionPerformed

    private void jTIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTIdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTIdActionPerformed

    private void jBPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBPesquisarActionPerformed
        try {

            listarSala();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "problemas no campo pesquisa" + ex);
        }
        desabilitaDados();
}//GEN-LAST:event_jBPesquisarActionPerformed

    private void jTPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTPesquisarActionPerformed
        try {
            // TODO add your handling code here:
            listarSala();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "problemas no campo pesquisa" + ex);
        }
}//GEN-LAST:event_jTPesquisarActionPerformed

    private void jBPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBPesquisaActionPerformed
        try {
           listarTodasSalas();
           listarSala();
            //listarSala();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "problemas no campo pesquisa" + ex);
        }
        desabilitaDados();
}//GEN-LAST:event_jBPesquisaActionPerformed

    private void jTPesquisar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTPesquisar1ActionPerformed
        
}//GEN-LAST:event_jTPesquisar1ActionPerformed

    private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalvarActionPerformed
        if (verificaDados()) {
            cadastro();
            try {
               listarTodasSalas();
               
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "problemas no campo salvar" + ex);
            }
            JOptionPane.showMessageDialog(null, "Sala salva com sucesso!!");
            desabilitaDados();
            jBAlterar.setEnabled(false);
            jBSalvar.setEnabled(false);
            jBRemover.setEnabled(false);
        }
}//GEN-LAST:event_jBSalvarActionPerformed

    private void jBAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAlterarActionPerformed
        try {
            alteraSala();
             listarTodasSalas();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "problemas no botao alterar" + ex);

        }
        desabilitaDados();
        jBAlterar.setEnabled(false);
        jBSalvar.setEnabled(false);
        jBRemover.setEnabled(false);
}//GEN-LAST:event_jBAlterarActionPerformed

    private void jBRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRemoverActionPerformed
        try {
            excluirSala();
            listarTodasSalas();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "problemas no botao excluir" + ex);
        }
        desabilitaDados();
        jBAlterar.setEnabled(false);
        jBSalvar.setEnabled(false);
        jBRemover.setEnabled(false);
}//GEN-LAST:event_jBRemoverActionPerformed

    private void jBFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBFecharActionPerformed
        dispose();
}//GEN-LAST:event_jBFecharActionPerformed

    private void jMenuSalaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSalaActionPerformed
        dispose();
        new CadastroDeSala().show();
}//GEN-LAST:event_jMenuSalaActionPerformed

    private void jMenuEquipamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuEquipamentoActionPerformed
        dispose();
        new CadastroDeEquipamento().show();
}//GEN-LAST:event_jMenuEquipamentoActionPerformed

    private void jMenuSairMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuSairMouseClicked
        dispose();
}//GEN-LAST:event_jMenuSairMouseClicked

    private void jMenuSalaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuSalaMouseClicked
        dispose();
        new CadastroDeSala().show();
    }//GEN-LAST:event_jMenuSalaMouseClicked

    private void jMenuEquipamentoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuEquipamentoMouseClicked
       dispose();
       new CadastroDeEquipamento().show();
    }//GEN-LAST:event_jMenuEquipamentoMouseClicked

    private void jMenuLaboratorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuLaboratorioActionPerformed
        dispose();
        new CadastroDeLaboratório().show();
    }//GEN-LAST:event_jMenuLaboratorioActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadastroDeSala().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAlterar;
    private javax.swing.JButton jBFechar;
    private javax.swing.JButton jBNovo;
    private javax.swing.JButton jBPesquisa;
    private javax.swing.JButton jBPesquisar;
    private javax.swing.JButton jBRemover;
    private javax.swing.JButton jBSalvar;
    private javax.swing.JComboBox jCSituacao;
    private javax.swing.JComboBox jCTipo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuEquipamento;
    private javax.swing.JMenuItem jMenuLaboratorio;
    private javax.swing.JMenu jMenuSair;
    private javax.swing.JMenuItem jMenuSala;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTAndar;
    private javax.swing.JTextField jTId;
    private javax.swing.JTextField jTNumLugares;
    private javax.swing.JTextField jTPesquisar;
    private javax.swing.JTextField jTPesquisar1;
    private javax.swing.JTextField jTPredio;
    private javax.swing.JTable jTTabela;
    // End of variables declaration//GEN-END:variables
//metodos ...

    public void habilitaDados() {
        // jTId.setEditable(true);
        jTAndar.setEditable(true);
        jTNumLugares.setEditable(true);
        jTPredio.setEditable(true);
        jCTipo.setEditable(true);
        //jCTipo.enable(true);
       // jCSituacao.enable(true);


    }

    public void desabilitaDados() {
        jTId.setEditable(false);
        jTAndar.setEditable(false);
        jTNumLugares.setEditable(false);
        jTPredio.setEditable(false);
       jCTipo.enable(false);
       // jCSituacao.enable(false);

    }

    public void cadastro() {

        try {

            Sala sala = new Sala();
            sala.setAndar(Integer.parseInt(jTAndar.getText()));
            sala.setPredio(jTPredio.getText());
            sala.setNumLugares(Integer.parseInt(jTNumLugares.getText())); //Sala de aula, Sala de reunião, Auditório

            if (jCTipo.getSelectedItem() == "Sala de aula") {
                sala.setTipo("sala de aula");
            }
            if (jCTipo.getSelectedItem() == "Sala de reunião") {
                sala.setTipo("sala de reuniao");
            }
            if (jCTipo.getSelectedItem() == "Auditório") {
                sala.setTipo("auditorio");
            }
            if (jCSituacao.getSelectedItem() == "Disponível") {
                sala.setSituacao("disponivel");
            }
            if (jCSituacao.getSelectedItem() == "Alugada") {
                sala.setSituacao("alugada");
            }


            SalaDAO dao = new SalaDAO();
            dao.adiciona(sala);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "problemas no cadastro!!" + ex);
        }
    }

    public void listarSala() throws SQLException {

        if(jTPesquisar1.getText().equals("")){
            JOptionPane.showMessageDialog(null, "digite um ID de uma sala para pesquisar");
        }else{
        SalaDAO dao = new SalaDAO();
        salas = dao.getLista(Integer.parseInt(jTPesquisar1.getText()));
        mostraPesquisa(salas);
        }
    }
      public void listarTodasSalas() throws SQLException {

        SalaDAO dao = new SalaDAO();
        salas = dao.getListaSalas();
        mostraPesquisa(salas);
    }

    public boolean verificaDados() {

        if (!jTNumLugares.getText().equals("") && !jTAndar.getText().equals("") && !jTPredio.getText().equals("")) {
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "os campos Numero de lugares, Andar e tipo nao podem ser nulos!!");
            return false;
        }
    }

    private void alteraSala() throws SQLException {

        if (jTTabela.getSelectedRow() != -1) {
            if (verificaDados()) {
                Sala sala = new Sala();
                SalaDAO dao = new SalaDAO();

                sala.setId(Integer.parseInt(jTId.getText()));
                sala.setAndar(Integer.parseInt(jTAndar.getText()));
                sala.setNumLugares(Integer.parseInt(jTNumLugares.getText()));
                sala.setPredio(jTPredio.getText());
                if (jCTipo.getSelectedItem() == "Sala de aula") {
                    sala.setTipo("sala de aula");
                }
                if (jCTipo.getSelectedItem() == "Sala de reunião") {
                    sala.setTipo("sala de reuniao");
                }
                if (jCTipo.getSelectedItem() == "Auditório") {
                    sala.setTipo("auditorio");
                }
                if (jCSituacao.getSelectedItem() == "Disponível") {
                    sala.setSituacao("disponivel");
                }
                if (jCSituacao.getSelectedItem() == "Alugada") {
                    sala.setSituacao("alugada");
                }


                dao.altera(sala);
                JOptionPane.showMessageDialog(null, "sala alterado com sucesso!");
                desabilitaDados();

            }
        }
    }

    public void excluirSala() throws SQLException {
        int resp = JOptionPane.showConfirmDialog(this, "deseja realmente excluir esta Sala", "confirmação: ", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_NO_OPTION) { //por default, a resposta é sim!!
            SalaDAO dao = new SalaDAO();
            dao.remove(salas.get(jTTabela.getSelectedRow()));
            mostraPesquisa(salas);

        }

    }

    private void jTTabelaLinhaSelecionada(JTable tabela) {

        if (jTTabela.getSelectedRow() != -1) { //"-1" é o cod do erro quando se da quando exclui um contato
            habilitaDados();
            jBNovo.setEnabled(true);
            jBAlterar.setEnabled(true);
            jBSalvar.setEnabled(false);
            jBRemover.setEnabled(true);

            jTId.setText(String.valueOf(salas.get(tabela.getSelectedRow()).getId()));
            jTAndar.setText(String.valueOf(salas.get(tabela.getSelectedRow()).getAndar()));
            jTNumLugares.setText(String.valueOf(salas.get(tabela.getSelectedRow()).getNumLugares()));
            jTPredio.setText(salas.get(tabela.getSelectedRow()).getPredio());
            jCTipo.setSelectedItem(String.valueOf(salas.get(tabela.getSelectedRow()).getTipo()));
            jCSituacao.setSelectedItem(String.valueOf(salas.get(tabela.getSelectedRow()).getSituacao()));

        } else {
            jTId.setText("");
            jTAndar.setText("");
            jTNumLugares.setText("");
            jTPredio.setText("");

        }

    }

    private void mostraPesquisa(List<Sala> salas) {

        while (tmSala.getRowCount() > 0) { //vai pegar todas as linha selecionadas maiores que zero, é vai remove-las!
            tmSala.removeRow(0);
        }
        if (salas.isEmpty()) { //se contatos for vazio, ou seja, naum haver nehum cadastrado...
            JOptionPane.showMessageDialog(null, "nehum sala cadastrada");
        } else {
            String[] linha = new String[]{null, null, null, null, null, null}; //colocando null em todas as colunas
            for (int i = 0; i < salas.size(); i++) {
                tmSala.addRow(linha);
                tmSala.setValueAt(salas.get(i).getId(), i, 0);
                tmSala.setValueAt(salas.get(i).getTipo(), i, 1);
                tmSala.setValueAt(salas.get(i).getPredio(), i, 2);
                tmSala.setValueAt(salas.get(i).getAndar(), i, 3);
                tmSala.setValueAt(salas.get(i).getNumLugares(), i, 4);
                tmSala.setValueAt(salas.get(i).getSituacao(), i, 5);//"id", "tipo", "predio","andar", "Num.Lugares", "situação"
            }
        }
    }
}
